const { formatTime_emotion } = require("../../../../common/util/util")

Page({
    data: {
        xPageReady : true,
        xList:[]
    },

    onLoad: function (option) {
        this.xInit(option.id)
    },
    xtodetail: function (e ){
        let path = e.currentTarget.dataset.path;
        let param =e.currentTarget.dataset.param;
        wx.navigateTo({
          url: '/subtool/pages/community/detail/index?id='+ param,
        })
    },
    xInit: async function (id) {
        let that = this

        await wx.cloud.callFunction({
          name: 'station_message',
          data: {
            action: "get_station_message",
            dataObj:{
              primary_type:2,
              secondary_type:Number(id)
            }
          }
        }).then(res => {
            for(let index in res.result){
              let dts = formatTime_emotion(new Date(res.result[index].create_time));
              res.result[index].create_time=dts
              if(index<=res.result.length-1){
                if(res.result[index].is_read==0 && res.result[Number(index)+1].is_read==1){
                  res.result[index].show=true
                }else{
                  res.result[index].show=false
                }
                if(res.result[index].is_read==0 && res.result.length==1){
                  res.result[index].show=true
                }
              }else{
                res.result[index].show=false
              }
              
            }
            that.setData({
              xList:res.result,
              xPageReady : false
            })
        })

        
    },
})